feat: two-tier telemetry and slash command tracking#34
Merged
Conversation
…tracking - Buffered fire-and-forget telemetry client flushing every 5s to `POST /api/observability/ingest` - Two-tier init: authenticated users via `Control.account()` with Bearer token, anonymous users via `ALTIMATE_TELEMETRY_URL` env var - Track 7 event types: `session_start`, `session_end`, `generation`, `tool_call`, `bridge_call`, `error`, `command` - Instrument `processor.ts` with generation, tool call, and error tracking - Instrument `prompt.ts` with session lifecycle and slash command tracking - Instrument `bridge/client.ts` with bridge call duration tracking - Conditional Bearer header and 401 retry only for authenticated sessions - Ring buffer (200 max), 10s timeout, `unref()` timer, silent failure Co-Authored-By: Kai (Claude Opus 4.6) <noreply@anthropic.com>
3c93a9b to
3a5787a
Compare
Comment on lines
+98
to
+107
| let enabled = false | ||
| let authenticated = false | ||
| let buffer: Event[] = [] | ||
| let flushTimer: ReturnType<typeof setInterval> | undefined | ||
| let accountUrl = "" | ||
| let cachedToken = "" | ||
| let userEmail = "" | ||
| let sessionId = "" | ||
| let projectId = "" | ||
|
|
There was a problem hiding this comment.
Bug: The telemetry module uses shared global state, causing a race condition between concurrent sessions that leads to corrupted or lost telemetry data.
Severity: CRITICAL
Suggested Fix
Refactor the telemetry module to avoid using shared, module-level state. The telemetry state, including sessionId, projectId, and the enabled flag, should be scoped per-session. This could be achieved by passing a session-specific telemetry context object through the call stack or by using a context management system that supports asynchronous operations.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/altimate-code/src/telemetry/index.ts#L98-L107
Potential issue: The telemetry module uses shared, module-level state variables
(`enabled`, `sessionId`, `projectId`, etc.) across all concurrent sessions within a
single process. When multiple sessions run in parallel, a race condition occurs. One
session's call to `Telemetry.setContext` can overwrite the context of another, leading
to misattributed telemetry events. Furthermore, when one session completes and calls
`Telemetry.shutdown`, it disables telemetry globally by setting `enabled = false`,
causing all other active sessions to lose their telemetry data.
Did we get this right? 👍 / 👎 to inform future reviews.
anandgupta42
pushed a commit
that referenced
this pull request
Mar 17, 2026
feat: two-tier telemetry and slash command tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Control.account(), anonymous users send viaALTIMATE_TELEMETRY_URLenv var, no config = disabledcommandevent type captures/command,/skill, and MCP command invocations with name, source, and message IDCommits
feat: add observability telemetry to CLI— initial buffered telemetry client with session, generation, tool_call, bridge_call, error eventsfeat: two-tier telemetry (auth + anonymous) and slash command tracking— anonymous support + command event typeTest plan
altimate-code auth login→ run/init→ verify Bearer token in request, events in LangfuseALTIMATE_TELEMETRY_URL→ run session → verify no Bearer header, events still sent/init→ verifycommandevent withcommand_name: "init"andcommand_source: "command"npx tsc --noEmitpasses with zero new errorsGenerated with Kai